package co.yixiang.mall.biz.user.mapper;

import co.yixiang.mall.common.mall.dto.YxCommissionCalculateRatioDto;
import co.yixiang.mall.common.mall.dto.YxUserParentLevelDto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Repository
public interface YxUserRewardCalculationMapper {
   //用户推挤人及以上所有推荐人
   @Select("SELECT uid, partner_id AS parentid, level, rownumber  " +
           "FROM " +
           "  (SELECT @id AS _id, @rownumber := @rownumber + 1 AS rownumber, " +
           "    (SELECT " +
           "      @id := partner_id  " +
           "    FROM " +
           "      yx_user  " +
           "    WHERE " +
           "      uid IN ( _id )) AS ids  " +
           "  FROM " +
           "    yx_user t , " +
           "    (SELECT @rownumber:=0,@id := #{uid}) as a      " +
           "  ) id, " +
           "  yx_user DATA  " +
           "WHERE " +
           "  id._id != 0  " +
           "  AND FIND_IN_SET( DATA.uid, id._id )  " +
           "  AND uid != #{uid} ")
   List<YxUserParentLevelDto> queryParentLevel(@Param("uid") Integer uid);

   // 所有等级的佣金计算比例
   @Select("SELECT " +
           "grade, commission_ratio AS commissionRatio,generation, rebate,type ,capping " +
           "FROM " +
           "yx_system_user_level " +
           "ORDER BY grade asc")
   List<YxCommissionCalculateRatioDto> queryAllLevelRebateRatio();
}
